package OntoNotes;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileFilter;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.Charset;
import java.nio.charset.UnsupportedCharsetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;

import edu.berkeley.nlp.io.NumberRangeFileFilter;
import edu.berkeley.nlp.syntax.Tree;
import edu.berkeley.nlp.syntax.Trees;
import edu.berkeley.nlp.util.ConcatenationIterator;

public class FilenameCollectioni {


    public List<File> files;
   	public Charset charset;
    


    private List<File> getFilesUnder(String path, FileFilter fileFilter) {
      File root = new File(path);
      List<File> files = new ArrayList<File>();
      addFilesUnder(root, files, fileFilter);
      return files;
    }

    private void addFilesUnder(File root, List<File> files, FileFilter fileFilter) {
      if (! fileFilter.accept(root)) return;
      if (root.isFile()) {
        files.add(root);
        return;
      }
      if (root.isDirectory()) {
        SortedSet<File> children = new TreeSet<File>(Arrays.asList(root.listFiles()));
        for (File child : children) {
         
          addFilesUnder(child, files, fileFilter);
        }
      }
    }

    public FilenameCollectioni(String path, int lowFileNum, int highFileNum, Charset charset,String endString) {
      FileFilter fileFilter = new NumberRangeFileFilter(endString, lowFileNum, highFileNum, true);
      this.files = getFilesUnder(path, fileFilter);
//      for (File f : files) System.out.println(f.toString());
      this.charset = charset;
    }
    public FilenameCollectioni(String path, int lowFileNum, int highFileNum, String charsetName,String endString) {
    	this(path,lowFileNum,highFileNum,Charset.forName(charsetName),endString);
    }
     

}
